﻿Public Class DRUGITEMWUSE

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGITEMWUSE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryDRUGITEMWUSEGrid()

        DesignForm(Me)
        DesignGrid(MASDRGITEMWUSEGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Public Sub queryDRUGITEMWUSEGrid()
        Dim objSelectDataMasdrgitemwuse As New masdrgitemwuse
        objSelectDataMasdrgitemwuse.USEIDData(itemuseUSEIDCmb)
        objSelectDataMasdrgitemwuse.TIMEIDData(itemuseTIMEIDCmb)
        Dim masdrgitemwuseData As DataTable
        masdrgitemwuseData = connect.GetTable(objSelectDataMasdrgitemwuse.selectMasdrgitemwuse_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        MASDRGITEMWUSEGrid.PrimaryGrid.DataSource = masdrgitemwuseData
        'Me.refreshClinic()
    End Sub

    Private Sub MASDRGITEMWUSEGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGITEMWUSEGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        DTUIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการจับคู่").Value()
        PRDCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผลิตภัณฑ์").Value()
        DRGCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อทางการค้า").Value()
        DRGCODETxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสยา").Value()
        itemuseUSEIDCmb.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการใช้ยา").Value()
        itemuseTIMEIDCmb.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสเวลาการใช้ยา").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            statusMasdrgitemwuseChk.Checked = True
        Else
            statusMasdrgitemwuseChk.Checked = False
        End If
    End Sub

    Private Sub addMasdrgitemwuse_Click(sender As Object, e As EventArgs) Handles addMasdrgitemwuse.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If DRGCODETxt.Text.ToString.Length > 0 And itemuseUSEIDCmb.SelectedValue.ToString.Length > 0 And itemuseTIMEIDCmb.SelectedValue.ToString.Length > 0 Then
                    Dim objInsertData As New masdrgitemwuse
                    objInsertData.DRGCODE_ = DRGCODETxt.Tag

                    Dim getProductCode As DataTable
                    getProductCode = connect.GetTable("SELECT prdcode FROM drugitem WHERE drgcode = '" & DRGCODETxt.Tag & "'")
                    If getProductCode.Rows.Count > 0 Then
                        objInsertData.PRDCODE_ = Convert.ToInt32(getProductCode.Rows(0)("prdcode"))
                    Else
                        MsgBox("ไม่พบข้อมูลรหัสสินค้า")
                    End If

                    objInsertData.USEID_ = itemuseUSEIDCmb.SelectedValue
                    objInsertData.TIMEID_ = itemuseTIMEIDCmb.SelectedValue
                    objInsertData.STATUS_ = statusMasdrgitemwuseChk.Checked
                    objInsertData.insertMasdrgitemwuseData()

                    Dim objSelectDataMasdrgitemwuse As New masdrgitemwuse
                    objSelectDataMasdrgitemwuse.USEIDData(itemuseUSEIDCmb)
                    objSelectDataMasdrgitemwuse.TIMEIDData(itemuseTIMEIDCmb)
                    Dim masdrgitemwuseData As DataTable
                    masdrgitemwuseData = connect.GetTable(objSelectDataMasdrgitemwuse.selectMasdrgitemwuse_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    MASDRGITEMWUSEGrid.PrimaryGrid.DataSource = masdrgitemwuseData

                    DTUIDTxt.Text = ""
                    PRDCODETxt.Text = ""
                    DRGCODETxt.Text = ""
                    statusMasdrgitemwuseChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrgitemwuse_Click(sender As Object, e As EventArgs) Handles editMasdrgitemwuse.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DTUIDTxt.Text.ToString.Length > 0 And PRDCODETxt.Text.ToString.Length > 0 And DRGCODETxt.Text.ToString.Length > 0 And itemuseUSEIDCmb.SelectedValue.ToString.Length > 0 And itemuseTIMEIDCmb.SelectedValue.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลการจับคู่ดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrgitemwuse
                        objEditData.DTUID_ = DTUIDTxt.Text
                        objEditData.DRGCODE_ = DRGCODETxt.Tag
                        objEditData.PRDCODE_ = PRDCODETxt.Text
                        objEditData.USEID_ = itemuseUSEIDCmb.SelectedValue
                        objEditData.TIMEID_ = itemuseTIMEIDCmb.SelectedValue
                        objEditData.STATUS_ = statusMasdrgitemwuseChk.Checked
                        objEditData.editMasdrgitemwuseData()

                        Dim objSelectDataMasdrgitemwuse As New masdrgitemwuse
                        objSelectDataMasdrgitemwuse.USEIDData(itemuseUSEIDCmb)
                        objSelectDataMasdrgitemwuse.TIMEIDData(itemuseTIMEIDCmb)
                        Dim masdrgitemwuseData As DataTable
                        masdrgitemwuseData = connect.GetTable(objSelectDataMasdrgitemwuse.selectMasdrgitemwuse_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        MASDRGITEMWUSEGrid.PrimaryGrid.DataSource = masdrgitemwuseData

                        DTUIDTxt.Text = ""
                        PRDCODETxt.Text = ""
                        DRGCODETxt.Text = ""
                        statusMasdrgitemwuseChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgitemwuse")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgitemwuse")
        nextform.ShowDialog()
    End Sub
End Class